home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / CIconButton CDEF 1.0 / Sample Code / CIconButton PDemo.p < prev    next >
Encoding:
Text File  |  1993-10-15  |  4.3 KB  |  192 lines  |  [TEXT/PJMM]

  1. PROGRAM Sample;
  2. {}
  3. {    Sample program for using the CIconButton CDEF 1.0}
  4. {    by Ramon M. Felciano}
  5. {    felciano@camis.stanford.edu}
  6. {}
  7. {    ©1993 Ramon M. Felciano, All Rights Reserved}
  8. {}
  9.  
  10.     USES
  11.         CIconButtonIntf;
  12.  
  13.     CONST
  14.         kCIconButtonCDEFID = 20;
  15.  
  16.         kSampleMain = 650;
  17.         kSampleAlt = 700;
  18.         kSampleShell = 3210;
  19.  
  20.         atLeft = $08;
  21.         atRight = $0C;
  22.         atTop = $02;
  23.         atBottom = $03;
  24.     VAR
  25.         bPushButton: controlHandle;
  26.  
  27.  
  28.     FUNCTION GetRangedRdm (min, max: integer): integer;
  29.         VAR
  30.             qdRdm: longint;
  31.             range, t: longint;
  32.     BEGIN
  33.         qdRdm := BAND($FFFF, random);
  34.         range := max - min;
  35.         t := (qdRdm * range) DIV 65536;        {now 0 <= t <= range}
  36.         GetRangedRdm := t + min;
  37.     END;
  38.  
  39.  
  40.     PROCEDURE doContentClick (window: windowPtr; event: eventRecord);
  41.         VAR
  42.             mouse: point;
  43.             control: controlHandle;
  44.             checkbox, part: integer;
  45.     BEGIN
  46.         setPort(window);
  47.         mouse := event.where;
  48.         globalToLocal(mouse);
  49.         part := findControl(mouse, window, control);
  50.         IF ((part > 0) & (control <> NIL)) THEN
  51.             IF trackControl(control, mouse, NIL) <> 0 THEN
  52.                 BEGIN
  53.                     checkBox := GetCtlValue(control);
  54.                     checkBox := 1 - checkbox;
  55.                     SetCtlValue(control, checkbox);
  56.                     CASE (GetRangedRdm(1, 5)) OF
  57.                         1: 
  58.                             CIB_SetTitleOrientation(control, atLeft);
  59.                         2: 
  60.                             CIB_SetTitleOrientation(control, atRight);
  61.                         3: 
  62.                             CIB_SetTitleOrientation(control, atTop);
  63.                         4: 
  64.                             CIB_SetTitleOrientation(control, atBottom);
  65.                         OTHERWISE
  66.                             BEGIN
  67.                             END;
  68.                     END;
  69.                     invalRect(control^^.contrlRect);
  70.                 END;
  71.     END;
  72.  
  73.     PROCEDURE DrawMyWindow (whichWindow: windowPtr; btn: controlHandle);
  74.         VAR
  75.             textRect: rect;
  76.             theCopyright: str255;
  77.     BEGIN
  78.         FillRect(whichWindow^.portRect, gray);
  79.  
  80.         textRect := whichWindow^.portRect;
  81.         InsetRect(textRect, 5, 5);
  82.         textRect.bottom := textRect.top + 44;
  83.         FillRect(textRect, white);
  84.         FrameRect(textRect);
  85.  
  86.         theCopyright := CIB_GetCopyright(btn);
  87.         MoveTo(12, 18);
  88.         DrawString(theCopyright);
  89.  
  90.         MoveTo(12, 30);
  91.         DrawString('Click on the button to randomly change the title orientation.');
  92.  
  93.         MoveTo(12, 42);
  94.         DrawString('Click the close box or hit any key to quit.');
  95.  
  96.         UpdateControls(whichWindow, whichWindow^.visRgn);
  97.     END;
  98.  
  99.  
  100.     PROCEDURE doSimpleWindow;
  101.         LABEL
  102.             99;
  103.         VAR
  104.             done: boolean;
  105.             theWindow: windowPtr;
  106.             windowPart: integer;
  107.             wRecord: CWindowRecord;
  108.             limitRect: rect;
  109.             rWindow: rect;
  110.  
  111.             itemBox: rect;
  112.  
  113.             theEvent: eventRecord;
  114.             newWindowLoc: point;
  115.             savePort: grafPtr;
  116.             whichWindow: windowPtr;
  117.             tempClip: rgnHandle;
  118.             oe: osErr;
  119.     BEGIN
  120.         bPushButton := NIL;
  121.         done := false;
  122.         theWindow := NIL;
  123.         setRect(rWindow, 50, 50, 450, 200);
  124.         setRect(itemBox, 50, 50, 180, 120);
  125.         limitRect := screenBits.bounds;
  126.         theWindow := NewCWindow(@wRecord, rWindow, 'CIconButton demo', true, documentProc, windowPtr(-1), true, 0);
  127.         IF theWindow = NIL THEN
  128.             GOTO 99;
  129.         SetPort(theWindow);
  130.         PenNormal;
  131.         TextFont(geneva);
  132.         TextSize(9);
  133.         backPat(gray);
  134.  
  135.         ShowWindow(theWindow);
  136.         bPushbutton := newControl(theWindow, itemBox, 'Testing', false, kSampleAlt, kSampleMain, kSampleShell, (16 * kCIconButtonCDEFID), longint(NIL));
  137.         ShowControl(bPushbutton);
  138.         DrawMyWindow(theWindow, bPushButton);
  139.  
  140.  
  141.         REPEAT
  142.             IF WaitNextEvent(everyEvent, theEvent, 0, NIL) THEN
  143.                 CASE theEvent.what OF
  144.                     keyDown: 
  145.                         done := true;
  146.                     mouseDown: 
  147.                         BEGIN
  148.                             windowPart := FindWindow(theEvent.where, theWindow);
  149.                             CASE windowPart OF
  150.                                 inDrag: 
  151.                                     BEGIN
  152.                                         DragWindow(theWindow, theEvent.where, limitRect);
  153.                                         newWindowLoc := theWindow^.portRect.topLeft;
  154.                                         localToGlobal(newWindowLoc);
  155.                                         IF newWindowLoc.h MOD 8 <> 0 THEN
  156.                                             MoveWindow(theWindow, (newWindowLoc.h DIV 8) * 8, newWindowLoc.v, true);
  157.                                     END;
  158.                                 inGoAway: 
  159.                                     done := TrackGoAway(theWindow, theEvent.where);
  160.                                 inContent: 
  161.                                     doContentClick(theWindow, theEvent);
  162.                                 OTHERWISE
  163.                                     BEGIN
  164.                                     END;
  165.                             END;
  166.                         END;
  167.                     updateEvt: 
  168.                         BEGIN
  169.                             GetPort(savePort);
  170.                             whichWindow := windowPtr(theEvent.message);
  171.                             BeginUpdate(whichWindow);
  172.                             DrawMyWindow(theWindow, bPushButton);
  173.                             UpdateControls(whichWindow, whichWindow^.visRgn);
  174.                             EndUpdate(whichWindow);
  175.                             SetPort(savePort);
  176.                         END;
  177.                     OTHERWISE
  178.                         ;
  179.                 END;
  180.         UNTIL Done;
  181. 99:
  182.         IF theWindow <> NIL THEN
  183.             closeWindow(theWindow);
  184.     END;
  185.  
  186.  
  187.  
  188. BEGIN
  189.     InitCursor;
  190.  
  191.     doSimpleWindow;
  192. END.